<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            position: relative;
        }
        div{
            height: 1800px;
        }
    </style>
</head>
<body>
    <div>

    </div>
    <script>
        function topFunction() {
           let set=setInterval(function(){
                document.documentElement.scrollTop-=10;
               console.log( document.documentElement.scrollTop)
               if(document.documentElement.scrollTop==0){
                   console.log('关闭');
                   clearInterval(set)
               }
            },2000)
        }
        window.onscroll=function(){
            topFunction()
        }
    </script>
</body>
</html>